import { _decorator, Component, instantiate, Node, Prefab } from 'cc';
import AllyApi from '../api/AllyApi';
import { Ally, AllyOperateType } from '../entity/Ally';
import { UIManager } from '../common/UIManager';

import { EventManager } from '../event/EventManager';
import { InviteMeItem } from './InviteMeItem';
import { MeApplyItem } from './MeApplyItem';
import { OtherApplyItem } from './OtherApplyItem';
const { ccclass, property } = _decorator;

@ccclass('OtherApplyList')
export class OtherApplyList extends Component {
    @property(Node)
    empty:Node
    @property(Node)
    content:Node
    @property(Prefab)
    itemPrefab:Prefab
    start() {
        EventManager.instance.on(EventManager.EventType.RefreshOtherApplyList, this.getList, this)


        this.getList()
    }


    async getList(){
        await UIManager.instance.showLoading()
        let res = await AllyApi.Execute({
            op:AllyOperateType.Query
        })
        UIManager.instance.closeLoading()
        console.log(res)

        EventManager.instance.emit(EventManager.EventType.AllyRedDot, res.data)

        let list = res.data.ReqedList

        this.content.destroyAllChildren()
        for(let item of list){
            let node = instantiate(this.itemPrefab)
            this.content.addChild(node)

            node.getComponent(OtherApplyItem).setData(Ally.createByObj(item))
        }

        if(list.length > 0){
            this.empty.active = false
        }
    }
    
}


